/*
 * Copyright 2012 Marsrutai.lt
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package lt.marsrutai.mobile.android.fragment;

import lt.marsrutai.mobile.android.R;
import lt.marsrutai.mobile.android.activity.intent.StopTimesIntentHolder;
import lt.marsrutai.mobile.android.adapter.TransportStopBookmarkAdapter;
import lt.marsrutai.mobile.android.fragment.task.GetTransportStopBookmarksTaskFragment;
import lt.marsrutai.mobile.android.fragment.task.TaskFragment;
import lt.marsrutai.mobile.android.model.TransportStopBookmark;
import lt.marsrutai.mobile.android.task.GetTransportStopBookmarksTask;
import lt.marsrutai.mobile.android.widget.ListViewAdapter;
import android.view.View;
import android.widget.ListView;

/**
 * Fragment which displays transport stop bookmarks
 * 
 * @author Justas
 */
public class TransportStopBookmarksFragment extends BookmarksFragment<TransportStopBookmark> {

    private static final String GET_TRANSPORT_STOP_BOOKMARKS_TASK_FRAGMENT = "GetTransportStopBookmarksTaskFragment";

    @Override
    public int getNoBookmarksFoundMessage() {
        return R.string.bookmarks_not_found;
    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        sendStopData(getBookmarks().get(position));
    }

    @Override
    protected ListViewAdapter<TransportStopBookmark> createAdapter() {
        return new TransportStopBookmarkAdapter(getActivity());
    }

    private void sendStopData(TransportStopBookmark stopBookmark) {
        StopTimesIntentHolder intentHolder = new StopTimesIntentHolder(getActivity());
        intentHolder.setScopeFolder(stopBookmark.getScopeFolder());
        intentHolder.setScopeName(stopBookmark.getScopeName());
        intentHolder.setTransportId(stopBookmark.getTransportId());
        intentHolder.setScheduleId(stopBookmark.getScheduleId());
        intentHolder.setScheduleName(stopBookmark.getScheduleName());
        intentHolder.setScheduleTrackName(stopBookmark.getScheduleTrackName());
        intentHolder.setTrackId(stopBookmark.getTrackId());
        intentHolder.setTrackName(stopBookmark.getTrackName());
        intentHolder.setStopId(stopBookmark.getStopId());
        intentHolder.setStopName(stopBookmark.getStopName());
        intentHolder.setStopDirectionName(stopBookmark.getStopDirectionName());
        startActivity(intentHolder.getIntent());
    }

    @Override
    protected String getTaskBroadcastAction() {
        return GetTransportStopBookmarksTask.BROADCAST_ACTION;
    }

    @Override
    protected Class<? extends TaskFragment<?, ?, ?>> getTaskFragmentClass() {
        return GetTransportStopBookmarksTaskFragment.class;
    }

    @Override
    protected String getBookmarksTaskFragmentTag() {
        return GET_TRANSPORT_STOP_BOOKMARKS_TASK_FRAGMENT;
    }

}
